package mt.ordersList;

import static org.junit.Assert.*;
import mt.Order;
import mt.ordersList.OrderList.Type;

import org.junit.Test;

public class OrderListTest {

	@Test
	public void testOrderList() {
		OrderList ol = new OrderList();
		assertNotNull(ol);
	}

	@Test
	public void testGetLength() {
		OrderList ol = new OrderList();
		ol.add(Order.createBuyOrder("string1", "stock1", 100, 2));
		ol.add(Order.createBuyOrder("string1", "stock1", 500, 20));
		assertEquals(2, ol.getLength());
	}

	@Test
	public void testGetOrder() {
		OrderList ol = new OrderList();
		Order o = Order.createBuyOrder("string1", "stock1", 100, 2);
		ol.add(o);
		assertEquals(ol.getOrder(0), o);

	}

	@Test
	public void testRemoveOrder() {
		OrderList ol = new OrderList();
		Order o = Order.createBuyOrder("string1", "stock1", 100, 2);
		ol.add(o);
		assertFalse(ol.getOrderList().isEmpty());
		ol.removeOrder(o);
		assertTrue(ol.getOrderList().isEmpty());

	}

	@Test
	public void testUpdateOrder() {
		OrderList ol = new OrderList();
		Order o1 = Order.createBuyOrder("string1", "stock1", 100, 2);
		Order o2 = Order.createBuyOrder("string3", "stock1", 500, 22);

		ol.add(o1);
		ol.updateOrder(0, o2);

		assertEquals(ol.getOrder(0), o2);

	}

	@Test
	public void testAdd() {
		OrderList ol = new OrderList();
		Order o = Order.createBuyOrder("string1", "stock1", 100, 2);
		assertTrue(ol.getOrderList().isEmpty());
		ol.add(o);
		assertFalse(ol.getOrderList().isEmpty());

	}

	@Test
	public void testGetType() {
		OrderList ol = new OrderList();
		Order o = Order.createBuyOrder("string1", "stock1", 100, 2);
		ol.add(o);
		ol.setType(Type.MY_ORDER_LIST);
		assertEquals(ol.getType(), Type.MY_ORDER_LIST);

	}

	@Test
	public void testSetType() {
		OrderList ol = new OrderList();
		Order o = Order.createBuyOrder("string1", "stock1", 100, 2);
		ol.add(o);
		ol.setType(Type.MY_ORDER_LIST);
		assertEquals(ol.getType(), Type.MY_ORDER_LIST);
		ol.setType(Type.PUBLIC_ORDER_LIST);
		assertEquals(ol.getType(), Type.PUBLIC_ORDER_LIST);

	}

}
